// 账户相关通用js
$(function () {
    // 刷新验证码
    $('.checkcode_img').click(function () {
        this.src = this.src + "?";
    });
    
    // 注册
    $(':submit').click(function () {
        $('#register_form').find(".error_message").empty();
        $.ajax({
            url: '/register.html',
            type: 'POST',
            data: $('#register_form').serialize(),
            dataType: 'JSON',
            success: function (res) {
               if(res.status){
                   location.href = '/backend/base-info.html'
               }else{
                   for(var k in res.errors){
                       message_list = res.errors[k];
                       error_msg = res.errors[k][0]['messages'][0];
                       $('#register_form').find('[error='+ k +']').text(error_msg);
                   }
               }
            },
            error: function () {
                alert('网络繁忙，请稍候重试');
           }
        });
        return false;
    });

    // 登录
    $('#login').click(function () {
        $('#login_form').find('[error]').empty();
        $.ajax({
            url: '/login.html',
            type: 'POST',
            data: $('#login_form').serialize(),
            dataType: 'JSON',
            success: function (res) {
               if(res.status){
                   location.href='/';
               }else{
                   for(var k in res.errors){
                   message_list = res.errors[k];
                   error_msg = res.errors[k][0]['messages'][0];
                   $('#login_form').find('[error='+ k +']').text(error_msg);
               }
               }
            },
            error: function () {
                alert('网络繁忙，请稍候重试');
           }
        });
    });

    // 注销
    $('#logout').click(function () {
        $('#logoutcfmModel').modal();
    });

    // 确认注销
    $('#loggout_submit').click(function () {
        location.href = '/logout.html';
    });

});